﻿using NUnit.Framework;
using Castle.Windsor;
using System.Xml;
using Castle.Core.Configuration;
using Castle.Core.Configuration.Xml;
using Inovout.Repository;

namespace Castle.Facilities.NHibernateIntegration.Tests.Inovout
{
    [TestFixture]
    public class NHibernateExtensionFacilityTestCase
    {
        [Test]
        public void RegisterTest()
        {
            using (IWindsorContainer container = new WindsorContainer())
            {
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load("Configs\\DataSource.config");
                IConfiguration dataSourceConfiguration = XmlConfigurationDeserializer.GetDeserializedNode(xmlDocument.DocumentElement);

                IConfiguration nhFacilityConfiguration = new MutableConfiguration("facility");
                nhFacilityConfiguration.Attributes["type"] = typeof(NHibernateExtensionFacility).AssemblyQualifiedName;
                nhFacilityConfiguration.Attributes["id"] = "nhibernatefacility";
                nhFacilityConfiguration.Attributes["configurationBuilder"] = typeof(DatabaseConfigurationBuilder).AssemblyQualifiedName;
                nhFacilityConfiguration.Children.AddRange(dataSourceConfiguration.Children["databases"].Children);

                container.Kernel.ConfigurationStore.AddFacilityConfiguration(typeof(NHibernateExtensionFacility).FullName, nhFacilityConfiguration);
                container.AddFacility(typeof(NHibernateExtensionFacility).FullName, new NHibernateExtensionFacility(dataSourceConfiguration.Children["repositories"]));
                //   RepositoryInstaller repositoryInstaller = new RepositoryInstaller();
             //   repositoryInstaller.Install(container, null);

                ITypeSessionManager typeSessionManager = container.Resolve<ITypeSessionManager>();
                Assert.IsNotNull(typeSessionManager, "typeSessionManager is not null.");
            }
        }
    }
}
